<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Wyp
 */

namespace App\Modules\Live\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class LiveDetailsCriteria extends BaseCriterias
{
    protected $live_id;
    public function __construct($live_id)
    {
        $this->live_id = $live_id;
    }

    public function apply($model, RepositoryInterface $repository)
    {
        $live_id = $this->live_id;

        $select = [
            'hx_live.id',
            'hx_live.name',
            'hx_live.created_at',
            'hx_user.nick as nick',
            'hx_user.portrait',
            'hx_store.name as store',
            'hx_live.status',
            'hx_picture.image',
            'hx_live.url'
        ];

        $select = implode($select,',');

        return $model->selectRaw($select)
            ->leftJoin('user','live.user_id','user.id')
            ->leftJoin('picture','user.portrait','picture.id')
            ->leftJoin('user_store','user.id','user_store.uid')
            ->leftJoin('store','user_store.sid','store.id')
            ->where('live.id',$live_id)
            ;
    }

}